/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testing_class;

import java.awt.Color;
import java.io.File;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JFileChooser;
import stendcontrol.DataProcessor;

/**
 *
 * @author Asko
 */
public class ServersTest extends javax.swing.JFrame {
    
    private final int length =  5000 ;
                  
    JFileChooser jc = new JFileChooser() ;
    private final File file =  new File("E:\\Test");
    /**
     * Creates new form ServersTest
     */
    public ServersTest() {
        
        initComponents();
        jc.setCurrentDirectory(file);
        this.setLocationRelativeTo(null);
       
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pane = new org.math.plot.Plot2DPanel();
        jButton1 = new javax.swing.JButton();
        pane2 = new org.math.plot.Plot2DPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setForeground(java.awt.Color.white);

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pane, javax.swing.GroupLayout.DEFAULT_SIZE, 937, Short.MAX_VALUE)
                    .addComponent(pane2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pane, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pane2, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

     double res[] =  {10 , 15 , 23 , 36 , 52} ;
     double limit =  85 ; 
     DataProcessor dp = new DataProcessor();
        
     dp.setProcess(res, null);
     double xs[] = {1,2,3,4,5,6,7,8,9,10};
     double err =0.02 ;
     double x[] = {1,2,3,4,5};
     double lims[] = new double[xs.length];
        for (int i = 0; i < xs.length; i++) {
            lims[i] = limit ;
        }
      double aprx[][] = dp.approximateFunc( x, res);
      double resource = dp.findRemainingResource(limit, x, res);
      double safeRS   = dp.findSafeResource(limit, x, res);
      double period  = dp.findServicePeriod(limit, x, res);
        System.out.println("Safe resource -> " + safeRS);
        System.out.println("Remaining resource -> " + resource);
        System.out.println("Predictable service period -> " + period + "\n");
          
      double apx [] = new double [10];
      double beta0 = dp.getBeta0();
        System.out.println("Beta0 : " + beta0);
      double beta1 = dp.getBeta1();
        System.out.println("Beta1 : " + beta1);
        for (int i = 0; i < apx.length; i++) {
         apx[i] = xs[i]*beta1 + beta0 ;   
        }
         pane.setAxisLabels("t, лет","Е , Дж  ");
         
         pane.addScatterPlot(null, Color.green, xs, apx);
         pane.addLinePlot(null,Color.MAGENTA, xs, lims );        
         pane.addScatterPlot(null, Color.red, x, res);
        
//        
//        double x[] = new double[length];
//        for (int i = 0; i < x.length; i++) {
//            x[i] =  i  ;
//        }
//        
//        double [] my = getValues();
//        DataProcessor dp = new DataProcessor();
//        dp.setProcess(x, my);
//        double [] oth = dp.centeringProcess(x, my, 3);
//        double [] corrFunc = dp.corrFunc(x, oth, 37);
//         pane.addLinePlot(null,Color.BLUE,my);  
//         pane2.addLinePlot(null, Color.BLUE, oth);
        // pane3.addLinePlot(null, Color.GREEN,corrFunc);
        
        
    
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ServersTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ServersTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ServersTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ServersTest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ServersTest().setVisible(true);
            }
        });
    }
    
    public double [] getValues() {
      DataProcessor dp = new DataProcessor();
       double arr[] = new double[length];
         Random rand = new Random();
        for (int i = 0; i < arr.length; i++) {
            
            double  r = rand.nextInt(255) + 100*(Math.sin(i/50)+1)+1;
          //  arr[i] =  (r <192 && r>64) ? 0.2*(r -128)+128 : r;
            arr[i]  = r ;
        }
      return arr;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private org.math.plot.Plot2DPanel pane;
    private org.math.plot.Plot2DPanel pane2;
    // End of variables declaration//GEN-END:variables
}
